/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.vtcc.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import vn.com.fis.portal.vtcc.NoSuchSampleEntryException;
import vn.com.fis.portal.vtcc.model.SampleEntry;
import vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl;
import vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the sample entry service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author loind
 * @see SampleEntryPersistence
 * @see SampleEntryUtil
 * @generated
 */
public class SampleEntryPersistenceImpl extends BasePersistenceImpl<SampleEntry>
	implements SampleEntryPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link SampleEntryUtil} to access the sample entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = SampleEntryImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SAMPLECODE =
		new FinderPath(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryModelImpl.FINDER_CACHE_ENABLED, SampleEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySampleCode",
			new String[] {
				String.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SAMPLECODE =
		new FinderPath(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryModelImpl.FINDER_CACHE_ENABLED, SampleEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySampleCode",
			new String[] { String.class.getName() },
			SampleEntryModelImpl.SAMPLECODE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_SAMPLECODE = new FinderPath(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySampleCode",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryModelImpl.FINDER_CACHE_ENABLED, SampleEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryModelImpl.FINDER_CACHE_ENABLED, SampleEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the sample entry in the entity cache if it is enabled.
	 *
	 * @param sampleEntry the sample entry
	 */
	public void cacheResult(SampleEntry sampleEntry) {
		EntityCacheUtil.putResult(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryImpl.class, sampleEntry.getPrimaryKey(), sampleEntry);

		sampleEntry.resetOriginalValues();
	}

	/**
	 * Caches the sample entries in the entity cache if it is enabled.
	 *
	 * @param sampleEntries the sample entries
	 */
	public void cacheResult(List<SampleEntry> sampleEntries) {
		for (SampleEntry sampleEntry : sampleEntries) {
			if (EntityCacheUtil.getResult(
						SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
						SampleEntryImpl.class, sampleEntry.getPrimaryKey()) == null) {
				cacheResult(sampleEntry);
			}
			else {
				sampleEntry.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all sample entries.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(SampleEntryImpl.class.getName());
		}

		EntityCacheUtil.clearCache(SampleEntryImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the sample entry.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(SampleEntry sampleEntry) {
		EntityCacheUtil.removeResult(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryImpl.class, sampleEntry.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@Override
	public void clearCache(List<SampleEntry> sampleEntries) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (SampleEntry sampleEntry : sampleEntries) {
			EntityCacheUtil.removeResult(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
				SampleEntryImpl.class, sampleEntry.getPrimaryKey());
		}
	}

	/**
	 * Creates a new sample entry with the primary key. Does not add the sample entry to the database.
	 *
	 * @param sampleId the primary key for the new sample entry
	 * @return the new sample entry
	 */
	public SampleEntry create(long sampleId) {
		SampleEntry sampleEntry = new SampleEntryImpl();

		sampleEntry.setNew(true);
		sampleEntry.setPrimaryKey(sampleId);

		return sampleEntry;
	}

	/**
	 * Removes the sample entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param sampleId the primary key of the sample entry
	 * @return the sample entry that was removed
	 * @throws vn.com.fis.portal.vtcc.NoSuchSampleEntryException if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public SampleEntry remove(long sampleId)
		throws NoSuchSampleEntryException, SystemException {
		return remove(Long.valueOf(sampleId));
	}

	/**
	 * Removes the sample entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the sample entry
	 * @return the sample entry that was removed
	 * @throws vn.com.fis.portal.vtcc.NoSuchSampleEntryException if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public SampleEntry remove(Serializable primaryKey)
		throws NoSuchSampleEntryException, SystemException {
		Session session = null;

		try {
			session = openSession();

			SampleEntry sampleEntry = (SampleEntry)session.get(SampleEntryImpl.class,
					primaryKey);

			if (sampleEntry == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchSampleEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(sampleEntry);
		}
		catch (NoSuchSampleEntryException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected SampleEntry removeImpl(SampleEntry sampleEntry)
		throws SystemException {
		sampleEntry = toUnwrappedModel(sampleEntry);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, sampleEntry);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(sampleEntry);

		return sampleEntry;
	}

	@Override
	public SampleEntry updateImpl(
		vn.com.fis.portal.vtcc.model.SampleEntry sampleEntry, boolean merge)
		throws SystemException {
		sampleEntry = toUnwrappedModel(sampleEntry);

		boolean isNew = sampleEntry.isNew();

		SampleEntryModelImpl sampleEntryModelImpl = (SampleEntryModelImpl)sampleEntry;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, sampleEntry, merge);

			sampleEntry.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !SampleEntryModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((sampleEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SAMPLECODE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						sampleEntryModelImpl.getOriginalSampleCode()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SAMPLECODE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SAMPLECODE,
					args);

				args = new Object[] { sampleEntryModelImpl.getSampleCode() };

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SAMPLECODE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SAMPLECODE,
					args);
			}
		}

		EntityCacheUtil.putResult(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			SampleEntryImpl.class, sampleEntry.getPrimaryKey(), sampleEntry);

		return sampleEntry;
	}

	protected SampleEntry toUnwrappedModel(SampleEntry sampleEntry) {
		if (sampleEntry instanceof SampleEntryImpl) {
			return sampleEntry;
		}

		SampleEntryImpl sampleEntryImpl = new SampleEntryImpl();

		sampleEntryImpl.setNew(sampleEntry.isNew());
		sampleEntryImpl.setPrimaryKey(sampleEntry.getPrimaryKey());

		sampleEntryImpl.setSampleId(sampleEntry.getSampleId());
		sampleEntryImpl.setScientificName(sampleEntry.getScientificName());
		sampleEntryImpl.setSampleSynonym(sampleEntry.getSampleSynonym());
		sampleEntryImpl.setECatalog(sampleEntry.getECatalog());
		sampleEntryImpl.setSampleCode(sampleEntry.getSampleCode());
		sampleEntryImpl.setCatalogYear(sampleEntry.getCatalogYear());
		sampleEntryImpl.setOtherName(sampleEntry.getOtherName());
		sampleEntryImpl.setSampleOtherCode(sampleEntry.getSampleOtherCode());
		sampleEntryImpl.setSourceIsolation(sampleEntry.getSourceIsolation());
		sampleEntryImpl.setHistory(sampleEntry.getHistory());
		sampleEntryImpl.setSampleForeign(sampleEntry.getSampleForeign());
		sampleEntryImpl.setDomestic(sampleEntry.getDomestic());
		sampleEntryImpl.setDeposit(sampleEntry.getDeposit());
		sampleEntryImpl.setIsolationMethod(sampleEntry.getIsolationMethod());
		sampleEntryImpl.setIsolationTime(sampleEntry.getIsolationTime());
		sampleEntryImpl.setDepositionTime(sampleEntry.getDepositionTime());
		sampleEntryImpl.setIsolationPerson(sampleEntry.getIsolationPerson());
		sampleEntryImpl.setFd(sampleEntry.getFd());
		sampleEntryImpl.setDf(sampleEntry.getDf());
		sampleEntryImpl.setSampleLN(sampleEntry.getSampleLN());
		sampleEntryImpl.setCultivationMedium(sampleEntry.getCultivationMedium());
		sampleEntryImpl.setCultivationTemperature(sampleEntry.getCultivationTemperature());
		sampleEntryImpl.setPH(sampleEntry.getPH());
		sampleEntryImpl.setMostRecentCheckingDate(sampleEntry.getMostRecentCheckingDate());
		sampleEntryImpl.setSurvivability(sampleEntry.getSurvivability());
		sampleEntryImpl.setTypeStrain(sampleEntry.getTypeStrain());
		sampleEntryImpl.setNaturalStrain(sampleEntry.getNaturalStrain());
		sampleEntryImpl.setMutatedStrain(sampleEntry.getMutatedStrain());
		sampleEntryImpl.setProductionStrain(sampleEntry.getProductionStrain());
		sampleEntryImpl.setCellMorphology(sampleEntry.getCellMorphology());
		sampleEntryImpl.setCellPhoto(sampleEntry.getCellPhoto());
		sampleEntryImpl.setColonyPhoto(sampleEntry.getColonyPhoto());
		sampleEntryImpl.setSporePhoto(sampleEntry.getSporePhoto());
		sampleEntryImpl.setSequences(sampleEntry.getSequences());
		sampleEntryImpl.setGrowthCondition(sampleEntry.getGrowthCondition());
		sampleEntryImpl.setQuinone(sampleEntry.getQuinone());
		sampleEntryImpl.setGCContent(sampleEntry.getGCContent());
		sampleEntryImpl.setOtherCharacteristics(sampleEntry.getOtherCharacteristics());
		sampleEntryImpl.setApplications(sampleEntry.getApplications());
		sampleEntryImpl.setSampleReferences(sampleEntry.getSampleReferences());
		sampleEntryImpl.setCreateDate(sampleEntry.getCreateDate());
		sampleEntryImpl.setUpdateDate(sampleEntry.getUpdateDate());
		sampleEntryImpl.setBiosafety(sampleEntry.getBiosafety());
		sampleEntryImpl.setStatus(sampleEntry.getStatus());
		sampleEntryImpl.setStrainId(sampleEntry.getStrainId());

		return sampleEntryImpl;
	}

	/**
	 * Returns the sample entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the sample entry
	 * @return the sample entry
	 * @throws com.liferay.portal.NoSuchModelException if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public SampleEntry findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the sample entry with the primary key or throws a {@link vn.com.fis.portal.vtcc.NoSuchSampleEntryException} if it could not be found.
	 *
	 * @param sampleId the primary key of the sample entry
	 * @return the sample entry
	 * @throws vn.com.fis.portal.vtcc.NoSuchSampleEntryException if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public SampleEntry findByPrimaryKey(long sampleId)
		throws NoSuchSampleEntryException, SystemException {
		SampleEntry sampleEntry = fetchByPrimaryKey(sampleId);

		if (sampleEntry == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + sampleId);
			}

			throw new NoSuchSampleEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				sampleId);
		}

		return sampleEntry;
	}

	/**
	 * Returns the sample entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the sample entry
	 * @return the sample entry, or <code>null</code> if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public SampleEntry fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the sample entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param sampleId the primary key of the sample entry
	 * @return the sample entry, or <code>null</code> if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public SampleEntry fetchByPrimaryKey(long sampleId)
		throws SystemException {
		SampleEntry sampleEntry = (SampleEntry)EntityCacheUtil.getResult(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
				SampleEntryImpl.class, sampleId);

		if (sampleEntry == _nullSampleEntry) {
			return null;
		}

		if (sampleEntry == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				sampleEntry = (SampleEntry)session.get(SampleEntryImpl.class,
						Long.valueOf(sampleId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (sampleEntry != null) {
					cacheResult(sampleEntry);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
						SampleEntryImpl.class, sampleId, _nullSampleEntry);
				}

				closeSession(session);
			}
		}

		return sampleEntry;
	}

	/**
	 * Returns all the sample entries where sampleCode = &#63;.
	 *
	 * @param sampleCode the sample code
	 * @return the matching sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<SampleEntry> findBySampleCode(String sampleCode)
		throws SystemException {
		return findBySampleCode(sampleCode, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the sample entries where sampleCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param sampleCode the sample code
	 * @param start the lower bound of the range of sample entries
	 * @param end the upper bound of the range of sample entries (not inclusive)
	 * @return the range of matching sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<SampleEntry> findBySampleCode(String sampleCode, int start,
		int end) throws SystemException {
		return findBySampleCode(sampleCode, start, end, null);
	}

	/**
	 * Returns an ordered range of all the sample entries where sampleCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param sampleCode the sample code
	 * @param start the lower bound of the range of sample entries
	 * @param end the upper bound of the range of sample entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<SampleEntry> findBySampleCode(String sampleCode, int start,
		int end, OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SAMPLECODE;
			finderArgs = new Object[] { sampleCode };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SAMPLECODE;
			finderArgs = new Object[] { sampleCode, start, end, orderByComparator };
		}

		List<SampleEntry> list = (List<SampleEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_SAMPLEENTRY_WHERE);

			if (sampleCode == null) {
				query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_1);
			}
			else {
				if (sampleCode.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_3);
				}
				else {
					query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_2);
				}
			}

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(SampleEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (sampleCode != null) {
					qPos.add(sampleCode);
				}

				list = (List<SampleEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first sample entry in the ordered set where sampleCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param sampleCode the sample code
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching sample entry
	 * @throws vn.com.fis.portal.vtcc.NoSuchSampleEntryException if a matching sample entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public SampleEntry findBySampleCode_First(String sampleCode,
		OrderByComparator orderByComparator)
		throws NoSuchSampleEntryException, SystemException {
		List<SampleEntry> list = findBySampleCode(sampleCode, 0, 1,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("sampleCode=");
			msg.append(sampleCode);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchSampleEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last sample entry in the ordered set where sampleCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param sampleCode the sample code
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching sample entry
	 * @throws vn.com.fis.portal.vtcc.NoSuchSampleEntryException if a matching sample entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public SampleEntry findBySampleCode_Last(String sampleCode,
		OrderByComparator orderByComparator)
		throws NoSuchSampleEntryException, SystemException {
		int count = countBySampleCode(sampleCode);

		List<SampleEntry> list = findBySampleCode(sampleCode, count - 1, count,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("sampleCode=");
			msg.append(sampleCode);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchSampleEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the sample entries before and after the current sample entry in the ordered set where sampleCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param sampleId the primary key of the current sample entry
	 * @param sampleCode the sample code
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next sample entry
	 * @throws vn.com.fis.portal.vtcc.NoSuchSampleEntryException if a sample entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public SampleEntry[] findBySampleCode_PrevAndNext(long sampleId,
		String sampleCode, OrderByComparator orderByComparator)
		throws NoSuchSampleEntryException, SystemException {
		SampleEntry sampleEntry = findByPrimaryKey(sampleId);

		Session session = null;

		try {
			session = openSession();

			SampleEntry[] array = new SampleEntryImpl[3];

			array[0] = getBySampleCode_PrevAndNext(session, sampleEntry,
					sampleCode, orderByComparator, true);

			array[1] = sampleEntry;

			array[2] = getBySampleCode_PrevAndNext(session, sampleEntry,
					sampleCode, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected SampleEntry getBySampleCode_PrevAndNext(Session session,
		SampleEntry sampleEntry, String sampleCode,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_SAMPLEENTRY_WHERE);

		if (sampleCode == null) {
			query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_1);
		}
		else {
			if (sampleCode.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_3);
			}
			else {
				query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_2);
			}
		}

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(SampleEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (sampleCode != null) {
			qPos.add(sampleCode);
		}

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(sampleEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<SampleEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the sample entries.
	 *
	 * @return the sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<SampleEntry> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the sample entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of sample entries
	 * @param end the upper bound of the range of sample entries (not inclusive)
	 * @return the range of sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<SampleEntry> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the sample entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of sample entries
	 * @param end the upper bound of the range of sample entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<SampleEntry> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<SampleEntry> list = (List<SampleEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_SAMPLEENTRY);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_SAMPLEENTRY.concat(SampleEntryModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<SampleEntry>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<SampleEntry>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the sample entries where sampleCode = &#63; from the database.
	 *
	 * @param sampleCode the sample code
	 * @throws SystemException if a system exception occurred
	 */
	public void removeBySampleCode(String sampleCode) throws SystemException {
		for (SampleEntry sampleEntry : findBySampleCode(sampleCode)) {
			remove(sampleEntry);
		}
	}

	/**
	 * Removes all the sample entries from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (SampleEntry sampleEntry : findAll()) {
			remove(sampleEntry);
		}
	}

	/**
	 * Returns the number of sample entries where sampleCode = &#63;.
	 *
	 * @param sampleCode the sample code
	 * @return the number of matching sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countBySampleCode(String sampleCode) throws SystemException {
		Object[] finderArgs = new Object[] { sampleCode };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SAMPLECODE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_SAMPLEENTRY_WHERE);

			if (sampleCode == null) {
				query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_1);
			}
			else {
				if (sampleCode.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_3);
				}
				else {
					query.append(_FINDER_COLUMN_SAMPLECODE_SAMPLECODE_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (sampleCode != null) {
					qPos.add(sampleCode);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SAMPLECODE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of sample entries.
	 *
	 * @return the number of sample entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_SAMPLEENTRY);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the sample entry persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.vn.com.fis.portal.vtcc.model.SampleEntry")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<SampleEntry>> listenersList = new ArrayList<ModelListener<SampleEntry>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<SampleEntry>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(SampleEntryImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = SampleEntryPersistence.class)
	protected SampleEntryPersistence sampleEntryPersistence;
	@BeanReference(type = StrainEntryPersistence.class)
	protected StrainEntryPersistence strainEntryPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_SAMPLEENTRY = "SELECT sampleEntry FROM SampleEntry sampleEntry";
	private static final String _SQL_SELECT_SAMPLEENTRY_WHERE = "SELECT sampleEntry FROM SampleEntry sampleEntry WHERE ";
	private static final String _SQL_COUNT_SAMPLEENTRY = "SELECT COUNT(sampleEntry) FROM SampleEntry sampleEntry";
	private static final String _SQL_COUNT_SAMPLEENTRY_WHERE = "SELECT COUNT(sampleEntry) FROM SampleEntry sampleEntry WHERE ";
	private static final String _FINDER_COLUMN_SAMPLECODE_SAMPLECODE_1 = "sampleEntry.sampleCode IS NULL";
	private static final String _FINDER_COLUMN_SAMPLECODE_SAMPLECODE_2 = "sampleEntry.sampleCode = ?";
	private static final String _FINDER_COLUMN_SAMPLECODE_SAMPLECODE_3 = "(sampleEntry.sampleCode IS NULL OR sampleEntry.sampleCode = ?)";
	private static final String _ORDER_BY_ENTITY_ALIAS = "sampleEntry.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SampleEntry exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SampleEntry exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(SampleEntryPersistenceImpl.class);
	private static SampleEntry _nullSampleEntry = new SampleEntryImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<SampleEntry> toCacheModel() {
				return _nullSampleEntryCacheModel;
			}
		};

	private static CacheModel<SampleEntry> _nullSampleEntryCacheModel = new CacheModel<SampleEntry>() {
			public SampleEntry toEntityModel() {
				return _nullSampleEntry;
			}
		};
}